﻿#region
/*******************************************************************************
** File Name:		    DepartmentRepository.cs
** Creator:		        chao.jiang 
** EMail:               chao.jiang 
** Create date:	        
** Latest Modifier:
** Latest Modify date:
** Description:		    
** Modify History:
**
** Code Review:
**
** Version number:       1.0.0
*********************************************************************************/
#endregion
using System;
using System.Collections.Generic;
using Phoenix.Entity;
using Phoenix.Respository;
using IBatisNet.DataMapper;
using Phoenix.Data.IBatis;
using System.Collections;

namespace Phoenix.IBatisRepository
{
    public class DepartmentRepository : BaseIBatisDao,IDepartment
    {
    
		#region  Auto Generation

        public DepartmentRepository()
            : base("/Config/IBatis/86TCMap.Config")
        {

        }
        		
        public System.Int32 AddDepartment(EDepartment entity)
        {
			string stmtId = "DepartmentMap.InsertDepartment";
			 Object obj = base.SqlMapper.Insert(stmtId, entity);
			 return (System.Int32)obj;
        }
        
		public  EDepartment GetByDepartmentID (System.Int32 departmentID)
        {
			string stmtId = "DepartmentMap.SelectByDepartmentID";
			return base.SqlMapper.QueryForObject<EDepartment>(stmtId, departmentID);
        }
        
        public  void DeleteByDepartmentID (System.Int32 departmentID)
        {
			string stmtId = "DepartmentMap.DeleteByDepartmentID";
			base.SqlMapper.Update(stmtId, departmentID);
        }
        
        public  void UpdateByDepartmentID (EDepartment entity)
        {
			string stmtId = "DepartmentMap.UpdateByDepartmentID";
			base.SqlMapper.Update(stmtId, entity);
        }


		public  IList<EDepartment> GetAll ()
        {
			string stmtId = "DepartmentMap.SelectAll";
			return base.SqlMapper.QueryForList<EDepartment>(stmtId,null);
        }

		#endregion

        /// <summary>
        /// </summary>
        /// <param name="oldLevel">部门旧级别</param>
        /// <param name="newLevel">部门新级别</param>
        /// <param name="department">子部门</param>
        public void BatchUpdate(string oldLevel, string newLevel, EDepartment entity)
        {
            Hashtable ht = new Hashtable();
            ht.Add("oldLevel", oldLevel);
            ht.Add("newLevel", newLevel);

            UpdateByDepartmentID(entity);

            string stmtId = "DepartmentMap.UpdateLevel";
            base.SqlMapper.Update(stmtId, ht);
        }



    }
}

